#include "stdafx.h"
#include "Enemy.h"

extern int miss;
extern int window_x, window_y;
extern int level;

Enemy::Enemy(void)
{
	nobjects = 0;
	animcycle = 100000.0;
	iAnim = 0;
	lasttime = 0;
}

Enemy::~Enemy(void)
{
// 	int i;
// 	for( i=0 ; i<nobjects ; i++ )
// 		delete objects[i];
}

void Enemy::LoadObject( C3DOjbect * obj )
{
	objects[nobjects] = obj;

	nobjects++;
}

void Enemy::SetAnimationCycleTime( DWORD cycle )
{
	animcycle = cycle;
}

GLvoid Enemy::Init()										// Initialize An Object
{
	frame=0;										// Reset The Explosion Frame To Zero
	hit=FALSE;										// Reset Object Has Been Hit Status To False

	x = rand()%(640+1);
	y = rand()%(480/2+1) + 480/2;
	z = (rand()%100)*(-1);

	x /= 100.0;
	y /= 100.0;
	z /= 100.0;

	x = -5.0f + double(rand()%100) / 10.0;
	y = 2.0f+double(rand()%100) / 25.0;;
	z = -60.0f;
}

void Enemy::Update(DWORD ms)
{
	lasttime += ms;

	if( lasttime > animcycle )
	{
		iAnim++;
		if( iAnim >= nobjects )
			iAnim = 0;
	}

	z += 0.0050f*float(ms)*double(level);
	y -= 0.00050f*float(ms)*double(level);

	if ((z>-1.0f) && !hit)
	{
		miss+=1;
		hit=TRUE;
	}
}

void Enemy::Draw()				// Draw Object Using Requested Width, Height And Texture
{
	glPushMatrix();

	glTranslatef( x, y, z );
	objects[iAnim]->DrawObject();

	glPopMatrix();
}
